Skip to content

Report hook context and refused instruction files in context inspection (4.1-4.4) - #137

Merged
leonardoaraujosantos merged 5 commits into
mainfrom
feat/context-rules
Nov 17, 2026
Merged

leonardoaraujosantos merged 5 commits into
mainfrom
feat/context-rules

Conversation

@leonardoaraujosantos

Copy link
Copy Markdown
Contributor

Advances #93. Stacked on #123 (feat/managed-recovery-owner); retarget to main once #123 merges.

Summary

Finishes tasks 4.1–4.4 of complete-daily-coding-surfaces (rules and context inspection). I checked every 4.x clause against the system-context, configuration and tui deltas, the code and the tests. Most of the work was already on #123: rule discovery and precedence, AGENTS.override.md, validated globs, bounded assembly and instruction_limits, delivery fencing and withdrawal, restart, the inspection route, /context and doctor. This PR closes the two real gaps the audit found:

  1. Hook additional_context in context inspection. Committed hook context used to be counted inside history. It is now its own hook_context source with origin hook, both in the stored projection and in last_prepared_request. Two kinds of pending update were invisible before and are now reported:

    • Context queued by background hook handlers shows as pending_hook_contexts and pending_hook_context_tokens, and those tokens are added to next_request.
    • A compaction requested during a turn shows as compaction_pending, with a new compaction_pending assumption.

    The hook text is never returned. The TUI /context panel shows all of this. The queue and the state are read under the Session state lock, the same lock the Safe Boundary uses to commit, so a text is never counted both as pending and as committed. New delta scenario: "Hook context and queued updates in inspection".

  2. Refused non-rule instruction files are typed withheld entries. Project instruction files and imports refused because they resolve outside the project (new reason outside_project) or because read rules deny them (read_denied) used to be warnings only. They now appear in withheld_sources. cyber doctor lists them once by reason and no longer repeats the loader warning.

OpenAPI and the TypeScript SDK are regenerated. docs/local-core-guide.md, docs/features.md, tasks.md (4.1–4.4 checked off, with an audit note) and implementation.md are updated.

Decisions

  • Hook context is not a rule. Once-per-Epoch delivery, approval fencing and withdrawal do not apply to it. Inspection treats it only as a context source and a pending update.
  • Withheld imports are recorded by canonical path, the same as withheld rule imports. Only paths and reasons are stored or returned, never content or sizes.
  • Tasks 4.1–4.4 are checked off on local macOS arm64 evidence. Native platform acceptance is not claimed here and stays with task 7.2.

Tests

New:

  • cyber-server context_compaction: inspection_reports_hook_context_as_pending_then_as_its_own_source, inspection_reports_a_compaction_requested_during_a_turn, inspection_reports_instruction_files_refused_outside_the_project
  • cyber-tui: inspection_shows_pending_hook_context_and_compaction_without_hook_text

Extended:

  • cyber-server instructions unit tests: project_imports_stay_inside_the_project, the_read_gate_refuses_project_files_and_imports_but_not_global_files (typed withheld entries)
  • cyber-cli: doctor_warns_about_an_instruction_file_outside_the_project (regression: listed once, as outside_project) and doctor_refuses_protected_imports_and_project_files_under_a_broken_config

Results under nextest ci:

  • cyber-server: lib plus context_compaction, http, structured_root, tool_hook_effects, hook_receipts, prompt_hook_shutdown and fork_context: 645 passed
  • cyber-app --test instructions: 31 passed
  • cyber-tools --test instruction_config: 2 passed
  • cyber-tui --lib: 687 passed
  • cyber-cli doctor tests (--bin cyber and --test cli): passed

Other checks, all passing:

  • SDK: typecheck and tests (139), generate_sdk.py --check
  • cargo fmt --check and cargo clippy --all-targets -D warnings
  • openspec validate --all --strict, spec_lint (0 errors), spec_inventory --check
  • cyber help-markdown matches docs/cli.md

Not covered

  • Native platform acceptance (Linux x64/ARM, macOS Intel, Windows); tracked under 7.2.
  • Hook additional_context is not redacted before it reaches the model. The redaction requirement covers tool output only, so changing this needs a spec decision.
  • Unresolvable, cyclic or too-deep imports remain warnings. They are not withheld sources.

Committed hook additional_context is now its own hook_context source
(origin hook) instead of being folded into history, in both the stored
projection and the last prepared request. Context queued by background
hook handlers and a compaction requested during a turn are reported as
pending updates; queued hook context is added to the next-request
estimate and a pending compaction is listed as an assumption. The
/context panel shows both without hook text. OpenAPI/SDK regenerated.
Project instruction files and imports refused because they resolve
outside the project (outside_project) or because read rules deny them
(read_denied) were only warnings, so context inspection could not show
them. The loader now records them as typed withheld entries like rule
definitions; inspection lists them and doctor reports them once by
reason instead of repeating the loader warning.
The Safe Boundary commits queued hook context while holding the state
lock; reading the queue and the state under the same lock keeps an
inspection from counting a text both as pending and as committed.
@leonardoaraujosantos
leonardoaraujosantos changed the base branch from feat/managed-recovery-owner to main November 17, 2026 13:57
@leonardoaraujosantos
leonardoaraujosantos merged commit 54bbcce into main Nov 17, 2026
38 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant